﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Modules.franchise.data {
    import flash.utils.*;
    import Classes.*;
    import __AS3__.vec.*;

    public class FranchiseDataModel {

        private var m_ownerUid:String;
        private var m_ownerFirstName:String;
        private var m_franchiseData:FranchiseData;

        public function FranchiseDataModel(_arg1:String, _arg2:String, _arg3:FranchiseData){
            this.m_ownerUid = _arg1;
            this.m_ownerFirstName = _arg2;
            this.m_franchiseData = _arg3;
        }
        public function get ownerUid():String{
            return (this.m_ownerUid);
        }
        public function getFranchiseName(_arg1:String):String{
            var _local2:String = this.getOwnedFranchiseName(_arg1);
            return (_local2);
        }
        public function getPendingName(_arg1:String):String{
            var _local2:String = this.getOwnedFranchisePendingName(_arg1);
            return (_local2);
        }
        public function setFranchiseName(_arg1:String, _arg2:String):void{
            var _local3:OwnedFranchiseData = this.getOwnedFranchise(_arg2);
            if (!_local3){
                _local3 = new OwnedFranchiseData(_arg2, _arg1, null, new Dictionary(), 0);
                this.addOwnedFranchise(_local3);
            };
            _local3.franchiseName = _arg1;
        }
        public function setPendingName(_arg1:String, _arg2:String):void{
            var _local3:OwnedFranchiseData = this.getOwnedFranchise(_arg2);
            if (_local3){
                _local3.pendingName = _arg1;
            };
        }
        public function getFranchiseTypes():Vector.<String>{
            var _local2:OwnedFranchiseData;
            var _local1:Vector.<String> = new Vector.<String>();
            for each (_local2 in this.m_franchiseData.ownedFranchises) {
                _local1.push(_local2.franchiseType);
            };
            return (_local1);
        }
        public function getFranchise(_arg1:String, _arg2:String):FranchiseExpansionData{
            var _local3:Dictionary = this.getFranchiseMapByType(_arg1);
            return (_local3[_arg2]);
        }
        public function getFranchiseCount():Number{
            var _local2:OwnedFranchiseData;
            var _local3:FranchiseExpansionData;
            var _local1:Number = 0;
            for each (_local2 in this.m_franchiseData.ownedFranchises) {
                for each (_local3 in _local2.locations) {
                    _local1++;
                };
            };
            return (_local1);
        }
        public function getBusinessCount():Number{
            var _local2:OwnedFranchiseData;
            var _local1:Number = 0;
            for each (_local2 in this.m_franchiseData.ownedFranchises) {
                _local1++;
            };
            return (_local1);
        }
        public function getFranchiseCountByType(_arg1:String):Number{
            return (this.getFranchisesByType(_arg1).length);
        }
        public function getFranchiseCountByLocation(_arg1:String):Number{
            return (this.getFranchisesByLocation(_arg1).length);
        }
        public function getFranchisesByType(_arg1:String):Vector.<FranchiseExpansionData>{
            var _local4:FranchiseExpansionData;
            var _local2:Vector.<FranchiseExpansionData> = new Vector.<FranchiseExpansionData>();
            var _local3:Dictionary = this.getFranchiseMapByType(_arg1);
            for each (_local4 in _local3) {
                _local2.push(_local4);
            };
            return (_local2);
        }
        public function getFranchisesByLocation(_arg1:String):Vector.<FranchiseExpansionData>{
            var _local3:OwnedFranchiseData;
            var _local4:FranchiseExpansionData;
            var _local2:Vector.<FranchiseExpansionData> = new Vector.<FranchiseExpansionData>();
            for each (_local3 in this.m_franchiseData.ownedFranchises) {
                _local4 = _local3.locations[_arg1];
                if (_local4){
                    _local2.push(_local4);
                };
            };
            return (_local2);
        }
        public function getFriendFranchiseCount():Number{
            var _local2:Dictionary;
            var _local3:FriendFranchiseData;
            var _local1:Number = 0;
            for each (_local2 in this.m_franchiseData.friendFranchises) {
                for each (_local3 in _local2) {
                    _local1++;
                };
            };
            return (_local1);
        }
        public function getFriendFranchiseCountByUid(_arg1:String):Number{
            return (this.getFriendFranchisesByUid(_arg1).length);
        }
        public function getFriendFranchisesByUid(_arg1:String):Vector.<FriendFranchiseData>{
            var _local3:String;
            var _local4:Dictionary;
            var _local5:FriendFranchiseData;
            var _local2:Vector.<FriendFranchiseData> = new Vector.<FriendFranchiseData>();
            for (_local3 in this.m_franchiseData.friendFranchises) {
                if (_local3 == _arg1){
                    _local4 = this.m_franchiseData.friendFranchises[_arg1];
                    for each (_local5 in _local4) {
                        _local2.push(_local5);
                    };
                    break;
                };
            };
            return (_local2);
        }
        public function addFranchise(_arg1:FranchiseExpansionData, _arg2:String):void{
            var _local3:Dictionary = this.getFranchiseMapByType(_arg1.franchiseType);
            if (((_local3) && (!(_local3[_arg2])))){
                _local3[_arg2] = _arg1;
            };
        }
        public function removeFranchise(_arg1:String, _arg2:String):FranchiseExpansionData{
            var _local3:FranchiseExpansionData;
            var _local4:Dictionary = this.getFranchiseMapByType(_arg1);
            if (_local4){
                _local3 = _local4[_arg2];
                delete _local4[_arg2];
            };
            return (_local3);
        }
        public function getHeadquartersType(_arg1:String):String{
            var _local2:String;
            var _local3:Item = Global.gameSettings.getItemByName(_arg1);
            if (_local3){
                _local2 = _local3.headquartersName;
            };
            return (_local2);
        }
        public function getOwnsFranchise(_arg1:String):Boolean{
            var _local2:OwnedFranchiseData = this.getOwnedFranchise(_arg1);
            if (_local2){
                return (true);
            };
            return (false);
        }
        private function getOwnedFranchiseName(_arg1:String):String{
            var _local2:String;
            var _local3:OwnedFranchiseData = this.getOwnedFranchise(_arg1);
            if (_local3){
                _local2 = _local3.franchiseName;
            };
            if (!_local2){
                _local2 = this.getDefaultFranchiseName(_arg1, this.m_ownerUid);
            };
            return (_local2);
        }
        private function getOwnedFranchisePendingName(_arg1:String):String{
            var _local2:String;
            var _local3:OwnedFranchiseData = this.getOwnedFranchise(_arg1);
            if (_local3){
                _local2 = _local3.pendingName;
            };
            return (_local2);
        }
        public function getOwnedFranchise(_arg1:String):OwnedFranchiseData{
            var _local3:OwnedFranchiseData;
            var _local2:OwnedFranchiseData;
            for each (_local3 in this.m_franchiseData.ownedFranchises) {
                if (_local3.franchiseType == _arg1){
                    _local2 = _local3;
                    break;
                };
            };
            return (_local2);
        }
        public function getOwnedFranchises():Vector.<OwnedFranchiseData>{
            return (this.m_franchiseData.ownedFranchises);
        }
        public function getDefaultFranchiseName(_arg1:String, _arg2:String):String{
            var _local3:String;
            if (_arg2 == Global.player.uid){
                _local3 = Global.player.firstName;
            } else {
                _local3 = Global.player.getFriendFirstName(_arg2);
            };
            if (!_local3){
                _local3 = ZLoc.t("Dialogs", "DefaultFriendName");
            };
            var _local4:String = ((Global.player.snUser.gender)=="M") ? ZLoc.instance.MASC : ZLoc.instance.FEM;
            return (ZLoc.t("Dialogs", "rename_business_inputField", {
                name:ZLoc.tn(_local3, _local4),
                item:ZLoc.t("Items", (_arg1 + "_friendlyName"))
            }));
        }
        private function getFranchiseMapByType(_arg1:String):Dictionary{
            var _local3:OwnedFranchiseData;
            var _local2:Dictionary = new Dictionary();
            for each (_local3 in this.m_franchiseData.ownedFranchises) {
                if (_local3.franchiseType == _arg1){
                    _local2 = _local3.locations;
                    break;
                };
            };
            return (_local2);
        }
        public function addOwnedFranchise(_arg1:OwnedFranchiseData):void{
            var _local2:OwnedFranchiseData;
            if (_arg1){
                _local2 = this.getOwnedFranchise(_arg1.franchiseType);
                if (!_local2){
                    this.m_franchiseData.ownedFranchises.push(_arg1);
                };
            };
        }

    }
}//package Modules.franchise.data 
